package com.js.service.impl;

import com.js.entity.DDormitoryinfo;
import com.js.dao.DDormitoryinfoDao;
import com.js.service.DDormitoryinfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DDormitoryinfo)表服务实现类
 *
 * @author makejava
 * @since 2022-06-15 13:43:04
 */
@Service("dDormitoryinfoService")
public class DDormitoryinfoServiceImpl implements DDormitoryinfoService {
    @Resource
    private DDormitoryinfoDao dDormitoryinfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param dId 主键
     * @return 实例对象
     */
    @Override
    public DDormitoryinfo queryById(Integer dId) {
        return this.dDormitoryinfoDao.queryById(dId);
    }

    /**
     * 分页查询
     *
     * @param dDormitoryinfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DDormitoryinfo> queryByPage(DDormitoryinfo dDormitoryinfo, PageRequest pageRequest) {
        long total = this.dDormitoryinfoDao.count(dDormitoryinfo);
        return new PageImpl<>(this.dDormitoryinfoDao.queryAllByLimit(dDormitoryinfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dDormitoryinfo 实例对象
     * @return 实例对象
     */
    @Override
    public DDormitoryinfo insert(DDormitoryinfo dDormitoryinfo) {
        this.dDormitoryinfoDao.insert(dDormitoryinfo);
        return dDormitoryinfo;
    }

    /**
     * 修改数据
     *
     * @param dDormitoryinfo 实例对象
     * @return 实例对象
     */
    @Override
    public DDormitoryinfo update(DDormitoryinfo dDormitoryinfo) {
        this.dDormitoryinfoDao.update(dDormitoryinfo);
        return this.queryById(dDormitoryinfo.getDId());
    }

    /**
     * 通过主键删除数据
     *
     * @param dId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer dId) {
        return this.dDormitoryinfoDao.deleteById(dId) > 0;
    }
    /**
    * 查询所有
    * @return 列表
    */
    @Override
    public List<DDormitoryinfo> queryAll(){
        return this.dDormitoryinfoDao.queryAll();
    }
}
